import 'sightable.dart';

class Focus {
  static Focus instance = Focus();
  static Focus get current {
    if (instance.overlays.isEmpty) {
      return instance;
    } else {
      return instance.overlays.last;
    } 
  }
  List<Focus>overlays = [];
  Sightable point;
  
  String sight(){
    if (overlays.isEmpty) {
      return point.optionCommandsDesc();
    } else {
      return overlays.last.point.optionCommandsDesc();
    }
  }

  void moveTo(Sightable next){
    if (next != null) {
      next.setPreview(this.point);
    }
    
    this.point = next;
    print('来到[${this.point.name}]');
  }

  void moveToPreview(Sightable current){
    print('返回[${current.preview.name}]');
    this.point = current.preview;
    current.setPreview(null);
  }

  void back() {
    moveToPreview(this.point);
  }
}